{include file="common/pc/header" title="定时任务运行" /}

<style>
    .execBtn {
        margin-top: 10px;
        margin-bottom: 10px;
    }

    .info-item {
        height: 30px;
        line-height: 30px;
    }

    #result {
        height: 500px;
    }
</style>

<div class="layui-row">
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>任务名称: {$task.title}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>任务标识: {$task.name}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>任务ID: {$task.id}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>任务状态: {$task.state}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>cron表达式: {$task.cron}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>任务超时秒数: {$task.timeout}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 info-item">
        <label>是否可重入: {$task.overlap}</label>
    </div>
    <div class="layui-col-xs10 layui-col-xs-offset2 execBtn">
        <button class="layui-btn" id="exec">手动触发</button>
    </div>

    <div class="layui-col-xs9 layui-col-xs-offset2">
        <textarea class="layui-textarea" id="result" readonly style="display: none;"></textarea>
    </div>
</div>

<script>
    $(document).on("click", "#exec", function () {
        layer.confirm("是否确认手动触发任务【" + "{$task.title}" + "】?", function () {
            layer.prompt({
                formType: 0,
                value: "",
                title: "请输入【" + "{$task.name}" + "】确认触发任务执行"
            }, function (value, index, elem) {
                if (value != "{$task.name}") {
                    layer.alert("输入错误");
                    return;
                }

                g.loading();

                $.post('/core/task/runCron', {'cronTaskId': "{$task.id}"}, function (res) {
                    g.loading(false);

                    layer.close(index);
                    layer.closeAll('dialog');

                    $("#result").show();
                    $("#result").val("本次任务执行结果如下：\n" + res);
                }, "html").error(function (xhr, type, msg) {
                    g.loading(false);
                    if (xhr.readyState == 4) {
                        alert("网络请求错误" + (msg ? (": " + msg) : ""));
                    }
                });
            });
        });
    });

</script>


{include file="common/pc/footer"/}